package io.renren.modules.edu.controller;

import io.renren.common.utils.JacksonUtils;
import io.renren.common.utils.PageData;
import io.renren.common.utils.Result;
import io.renren.modules.edu.dto.TEduScientificDTO;
import io.renren.modules.edu.dto.TEduTrainDTO;
import io.renren.modules.edu.entity.TEduScientificEntity;
import io.renren.modules.edu.entity.TEduTrainEntity;
import io.renren.modules.edu.service.TEduTrainService;
import io.renren.modules.edu.vo.TEduScientificVO;
import io.renren.modules.edu.vo.TEduTrainVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 培训管理表
 *
 * @author zwp zwp
 * @since 1.0.0 2022-07-11
 */
@RestController
@RequestMapping("edu/tedutrain")
@Api(tags="培训管理表")
public class TEduTrainController {

    @Autowired
    private TEduTrainService tEduTrainService;

    @GetMapping("queryPageData")
    @ApiOperation("培训管理信息分页")
    public Result<PageData<TEduTrainVO>> queryPageData(@RequestParam Map<String, Object> params){
        PageData<TEduTrainVO> pageData = tEduTrainService.queryPageData(params);
        return new Result<PageData<TEduTrainVO>>().ok(pageData);
    }

    @GetMapping("queryTrainById/{id}")
    @ApiOperation("根据id获取培训管理信息")
    public Result<TEduTrainVO> queryTrainById(@PathVariable Long id){
        TEduTrainVO tEduTrainVO = tEduTrainService.queryTrainById(id);
        return new Result<TEduTrainVO>().ok(tEduTrainVO);
    }

    @PostMapping("/confirmTrain/{id}")
    @ApiOperation("参与报名")
    public Result<Map<String, Object>> confirmTrain(@PathVariable Long id) {
        tEduTrainService.confirmTrain(id);
        return new Result<Map<String, Object>>();
    }

    @PostMapping
    @ApiOperation("培训活动录入")
    public Result<Map<String, Object>> onSubmit(@RequestBody TEduTrainDTO dto) {
        tEduTrainService.save(dto);
        return new Result<Map<String, Object>>();
    }

    @PutMapping
    @ApiOperation("培训活动更新")
    public Result<Map<String, Object>> update(@RequestBody TEduTrainDTO dto){
        tEduTrainService.getBaseMapper().updateById(JacksonUtils.obj2pojo(dto, TEduTrainEntity.class));
        return new Result<Map<String, Object>>();
    }

    @DeleteMapping("{id}")
    @ApiOperation("培训活动删除")
    public Result<Map<String, Object>> deleteTrain(@PathVariable Long id){
        tEduTrainService.deleteTrain(id);
        return new Result<Map<String, Object>>();
    }
}
